﻿/*
    Copyright 2010, 2011 Eric Wong
	contact@optimalcycling.com
	http://www.optimalcycling.com
	Optimal Cycling - Advanced power pacing program for cyclists
	
	This file is part of Optimal Cycling.

    Optimal Cycling is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Optimal Cycling is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Optimal Cycling.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.IO;
using System.Runtime.InteropServices;

namespace OptimalCycling.Interop
{
    #region Alias

    using sizeT = System.UInt32;
    using size_array = System.UInt32;

    // Allow us to easily switch between floats and double values
#if REAL_IS_DOUBLE
    using real = System.Double;
    using real2 = Vector2d;
    using real4 = Vector4d;
    using real8 = Vector8d;
#else
    using real = System.Single;
    using real2 = Vector2;
    using real4 = Vector4;
    using real8 = Vector8;
#endif

    #endregion

    /// <summary>
    /// Allows us to call a natively compiled C/C++ version of the Optimal Cycling kernel.
    /// (For debugging and testing purposes. The OpenCL compiled version of the kernel is recommended for use.)
    /// </summary>
    public static class OCCLibX86
    {
        #region C Lib Import

        [DllImport("OptimalCyclingC_Lib_x86.dll")]
        public static extern void OCSimRun(
            int currSolutionMode,
            int whichArray,
            sizeT numIndividuals,
            sizeT numSimPoints,

            IntPtr powerValA,
            IntPtr powerValB,
            IntPtr powerLimits,
            int powerAllSame,

            IntPtr fitness,

            IntPtr correspondingIndex,
            IntPtr bestFitIndex,
            sizeT numIndividPerPop,
            sizeT numPopulations,

            IntPtr coursePosPoints,
            IntPtr coursePosLinear,
            real coursePosLinearMax,
            IntPtr coursePosDirection,
            IntPtr coursePosInfo,
            IntPtr riderProp,
            IntPtr wind,
            IntPtr climate,

            IntPtr dragCoeffWheelYawAngles,
            IntPtr dragCoeffWheels,
            sizeT dragCoeffWheelsNumPts,

            IntPtr modelInfo,
            IntPtr iConstants,

            IntPtr randNumGenSeeds,
            IntPtr solverInfo,
            IntPtr solverVars,
            IntPtr powerMetricsInfo,
            IntPtr powerMetricsCriticals,

            IntPtr tempWorkingSpace,

            IntPtr bestTime,

            IntPtr bestPowerResults,
            IntPtr bestKinematics,

            IntPtr fitStats);

        #endregion
    }

    /// <summary>
    /// Allows us to call a natively compiled C/C++ version of the Optimal Cycling kernel.
    /// (For debugging and testing purposes. The OpenCL compiled version of the kernel is recommended for use.)
    /// </summary>
    public static class OCCLibX64
    {
        #region C Lib Import

        [DllImport("OptimalCyclingC_Lib_x64.dll")]
        public static extern void OCSimRun(
            int currSolutionMode,
            int whichArray,
            sizeT numIndividuals,
            sizeT numSimPoints,

            IntPtr powerValA,
            IntPtr powerValB,
            IntPtr powerLimits,
            int powerAllSame,

            IntPtr fitness,

            IntPtr correspondingIndex,
            IntPtr bestFitIndex,
            sizeT numIndividPerPop,
            sizeT numPopulations,

            IntPtr coursePosPoints,
            IntPtr coursePosLinear,
            real coursePosLinearMax,
            IntPtr coursePosDirection,
            IntPtr coursePosInfo,
            IntPtr riderProp,
            IntPtr wind,
            IntPtr climate,

            IntPtr dragCoeffWheelYawAngles,
            IntPtr dragCoeffWheels,
            sizeT dragCoeffWheelsNumPts,

            IntPtr modelInfo,
            IntPtr iConstants,

            IntPtr randNumGenSeeds,
            IntPtr solverInfo,
            IntPtr solverVars,
            IntPtr powerMetricsInfo,
            IntPtr powerMetricsCriticals,

            IntPtr tempWorkingSpace,

            IntPtr bestTime,

            IntPtr bestPowerResults,
            IntPtr bestKinematics,

            IntPtr fitStats);
        #endregion
    }
}